-- stage_attrib
-- created by zhuangsl
-- 进入下层概率增加属性

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    -- 进入下层触发触发
    trigger = function(who, prop, arg)
        -- 概率不符合
        if DungeonM.getRandSeed("stage_attrib") % 1000 >= tonumber(prop[3]) then
            return;
        end

        local arr = string.explode(prop[2], "+");
        local attrib = arr[1];
        local count = tonumber(arr[2])

        if attrib == "all" then
            -- 要求同时提高所有属性
            BonusM.doBonus({ 2, "attack", count, }, "prop stage_attrib");
            BonusM.doBonus({ 2, "magic",  count, }, "prop stage_attrib");
            BonusM.doBonus({ 2, "max_hp", count * 10, }, "prop stage_attrib");
            BonusM.doBonus({ 2, "max_mp", count * 10, }, "prop stage_attrib");
        elseif attrib == "random" then
            -- 随机属性
            local bonusList = { {2, "attack", count,},      {2, "magic", count,},
                                {2, "max_hp", count * 5,},  {2, "max_mp", count * 5,},
                                {2, "max_hp", count * 10,}, {2, "max_mp", count * 10,}};
            local bonus = bonusList[1 + DungeonM.getRandSeed("stage_attrib") % #bonusList];
            BonusM.doBonus(bonus, "prop stage_attrib");
        else
            BonusM.doBonus({ 2, attrib, count, }, "prop stage_attrib");
        end
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;

        local arr = string.explode(prop[2], "+");
        local attrib = arr[1];
        local rate = math.modf(prop[3] / 10)

        if attrib == "all" then
            -- 如果是全属性提升
            desc = row.append_desc;
            desc = string.gsub(desc, "{1}", rate);
        elseif attrib ~= "random" then
            -- 提升单个属性
            local fieldName = FieldsM.getFieldName(attrib);
            local value = tonumber(arr[2]);
            desc = string.gsub(desc, "{0}", fieldName);
            desc = string.gsub(desc, "{2}", value);
        end

        return desc;
    end,

    record = function(target, prop, path)
        return false;
    end
};